import { buildings, floors, rooms, beds, users } from './database.mjs'
export const statisticsRooms = (type = 'student') => {
  const buildFilters = buildings.filter((b) => b.type == type).map((b) => b.id)
  const floorFilters = floors.filter((f) => buildFilters.includes(f.building)).map((f) => f.id)
  const roomsFilter = rooms.filter((r) => floorFilters.includes(r.floor))
  // const roomIds = roomsFilter.map((r) => r.id)
  const userFilter = users.filter((u) => u.type == type)
  let full = 0
  let one = 0
  let zero = 0
  for (const room of roomsFilter) {
    const us = userFilter.filter((u) => (u.room == room.id))
    const bds = beds.filter((b) => (b.room == room.id))
    if (us.length == 0) {
      zero++
    }
    if (us.length == 1) {
      one++
    }
    if (us.length == bds.length) {
      full++
    }
  }
  return {
    total: roomsFilter.length,
    full,
    one,
    zero
  }
}
